<template lang="html">

  <div class="cartcontrol">
    <transition name="fadeRotate">
      <div class="cart-decrease" v-show="food.num>0" @click.stop.prevent="increaseCart()">
          <i class="icon-remove_circle_outline inner"></i>
      </div>
    </transition>
    <div class="cart-count" v-show="food.num>0">
      {{food.num}}
    </div>
    <div v-show="food.num==0" class="metoo" @click.stop.prevent="addCart">我也要</div>
    <div class="cart-add" @click.stop.prevent="addCart($event)">
      <i class="icon-add_circle"></i>
    </div>
  </div>

</template>

<script>
	export default{
		data(){
			return {
				chosetype:0,
				tostorefood:{}
			}
		},
		props:{
			food:{
				type:Object
			},
			index:{
				type:Number
			}
		},
		computed:{
			addtype:function(){
				if(this.food.ogndishespriceList.length==1&&(this.food.ogndishestasteList.length==0||!this.food.ogndishestasteList)&&(this.food.ogndishesavoList.length==0||!this.food.ogndishesavoList)&&(this.food.ogndishespackList.length==0||!this.food.ogndishespackList)){
					this.chosetype=0 //0是没有规格没有口味没有忌口没有套餐
				}
				else if((this.food.ogndishespackList.length>0&&this.food.ogndishespackList)){
					this.chosetype=1  //1是有套餐
				}
				else{
					this.chosetype=2//2是有多规格或者有口味选择或者有忌口选择
				}
			},
			shopfood:function(){
				if(this.chosetype==2){
				var postfood={
					taste:{
						avo:[]
					}
				}
				this.food.ogndishespriceList.forEach(function(guige){
					if(guige.chosed){
						postfood.specif=guige.unit.unitname
						postfood.price=guige.dishesprice
					}
				})
				this.food.ogndishestasteList.forEach(function(taste){
					if(taste.chosed){
						postfood.taste.tast=taste.taste.tastename
					}
				})
				this.food.ogndishesavoList.forEach(function(avo){
					if(avo.chosed){
						postfood.taste.avo.push(avo.avo.avoname)
					}
				})
				postfood.name=this.food.dishes.dishesname
				this.tostorefood=postfood;
			}
			}
		},
		methods:{
			addCart:function(event){
					this.food.num++;
				this.$emit('chan',this.index);
				this.$emit("cartadd",event.target)
			},
			increaseCart:function(){
//				if(!event._constructed){//如果不存在这个属性,则不执行下面的函数
//      return;
//  }
				this.food.num--;
			}
		}
	}
</script>

<style lang="stylus">

.cartcontrol
  vertical-align middle
  .metoo
    height 24px 
    background rgb(0,160,220)
    position absolute
    font-size 0.3rem
    right  0
    top 0
    width 100px
    border-radius 0.1rem
    line-height 24px
    color white
  .cart-decrease
    vertical-align middle  
    display inline-block
    transition: all .4s linear
    line-height 24px
    font-size 24px
    .inner
      color rgb(0,160,220)
      transition all 0.4s linear
    &.fadeRotate-enter-active, &.fadeRotate-leave-active
      transform translate3d(0,0,0)
      .inner
        display inline-block
        transform rotate(0)
    &.fadeRotate-enter, &.fadeRotate-leave-active
      opacity: 0
      transform translate3d(24px,0,0)
      .inner
        transform rotate(180deg)
  .cart-count
    display inline-block
    vertical-align middle
    font-size 10px
    color rgb(147,153,159)
    line-height 24px
    text-align center
  .cart-add
    display inline-block
    vertical-align middle
    font-size 24px
    color rgb(0,160,220)
    line-height 24px
</style>